package com.example.bootdemo.common.exception;
import com.example.bootdemo.common.result.ResultCode;

/**
 * 自定义异常类，用来抛出异常，信息从ResultCode来拿错误信息
 */
public class BizException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    protected String errorCode;
    /**
     * 错误信息
     */
    protected String errorMsg;

    public BizException() {
        super();
    }

    public BizException(ResultCode resultCode) {
        super(resultCode.code());
        this.errorCode = resultCode.code();
        this.errorMsg = resultCode.message();
    }

    public BizException(ResultCode resultCode, Throwable cause) {
        super(resultCode.code(), cause);
        this.errorCode = resultCode.code();
        this.errorMsg = resultCode.message();
    }

    public BizException(String errorMsg) {
        super(errorMsg);
        this.errorMsg = errorMsg;
    }

    public BizException(String errorCode, String errorMsg) {
        super(errorCode);
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    public BizException(String errorCode, String errorMsg, Throwable cause) {
        super(errorCode, cause);
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }


    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public String getMessage() {
        return errorMsg;
    }

    @Override
    public Throwable fillInStackTrace() {
        return this;
    }

}

